<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>使用weakMap实现栈</title>
    </head>
    <body></body>
    <script>
        class Stack {
            items = new WeakMap();
            constructor() {
                this.items.set(this, []);
            }
            push(element) {
                const s = this.items.get(this);
                s.push(element);
            }
            pop() {
                const s = this.items.get(this);
                const r = s.pop();
                return r;
            }
        }
    </script>
</html>
